(function(){ // 创建最外层匿名函数.
	window._$i = window.$i;//将别的框架定义的$暂存.
	var iBase = window.iBase = window.$i = function(selector) { 
		return new iBase.fn.init(selector); 
	};
	
	
	
	//Method
	iBase.fn = iBase.prototype = {
		init: function(selector) { 
			if(selector){
				this.selector = selector;
			} 
			return this; 
		},
		val: function(newValue) {
			if(!(this.selector && this.selector.indexOf('#') == 0 && this.selector.length != 1))
				return; //简单地判断传入值非法, 最好使用正则
			var id = this.selector.substring(1);
			var obj = document.getElementById(id);
			if(obj){//如果对象存在
				if(newValue == undefined)
					return obj.value;//获取目标对象的值.
				obj.value = newValue;// 将目标对象的value属性设置为newValue.
				return this; //为了使方法可以连续调用, 返回当前实例。
			}
		}
		
	};

	iBase.fn.init.prototype = iBase.fn;
})();

//扩展新的方法.
(function(o){
	o.noConflict = function(){
		window.$i = window._$i;//把$i还给在开始处取得的引用.
	};
	o.alert = function(arg){
		alert(arg);
	};
	o.id = function(id){
		return document.getElementById(id);
	};
	
	/*
	//Mediator
	var channels = {};
	var subscribe = function(channel,fn){
		if(!channels[channel]){
			channels[channel] = [];
		}
		channels[channel].push({context:this,callback:fn});
		return this;
	};
	var publish = function(channel){
		if(!channels[channel]){
			return false;
		}
		var args = Array.prototype.slice.call(arguments,1);
		for(var i=0,count = channels[channel].length;i<count;i++){
			var subscription = channels[channel][i];
			subscription.callback.apply(subscription.context,args);
		}
		return this;
	};
	
	o.publish=publish;
	o.subscribe=subscribe;
	o.installTo=function(obj){
		obj.subscribe = subscribe;
		obj.publish = publish;
	};
	*/
})(iBase);